package com.bird.servlet;

import java.io.IOException;
import java.net.URLDecoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bird.utils.HttpClientUtils;

public class AjaxServlet extends HttpServlet {

	/**
	 * Ajax请求获取小黄鸡的回复
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");  
	    response.setContentType("text/html;charset=UTF-8");  
	    
		String key = request.getParameter("key");
		key=URLDecoder.decode(key, "UTF-8");  
		
		HttpClientUtils utils = new HttpClientUtils();
		String answer = utils.SendGET(key);
		
		response.getWriter().write(answer);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
